package org.example.service;

import org.example.task.CountdownTask;
import org.example.task.TimePrintTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.ThreadPoolExecutor;

@Service
public class TaskService {

    // 注入线程池
    @Autowired
    private ThreadPoolExecutor taskExecutor;

    /**
     * 提交时间打印任务
     */
    public void submitTimePrintTask(String taskName) {
        taskExecutor.submit(new TimePrintTask(taskName));
    }

    /**
     * 提交倒计时任务
     */
    public void submitCountdownTask(String taskName, int seconds) {
        taskExecutor.submit(new CountdownTask(taskName, seconds));
    }

    /**
     * 关闭线程池
     */
    public void shutdownExecutor() {
        taskExecutor.shutdown();
    }
}
